package com.fzu.express.controller;


import com.fzu.express.utils.ApiException;
import com.fzu.express.utils.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 錯誤處理控制器
 *
 * @author zyq
 * @since 2022-10-27
 */
@RestController
public class ErrorController {

    @RequestMapping("/error/handle")
    public R error(HttpServletRequest request) {
        ApiException e = (ApiException) request.getAttribute("exception");
        return R.error().code(e.getCode()).message(e.getMessage());
    }

}

